<?php

    $mikron->Page->StartBody();

    $pageindex = 4;
    $pacientcode = isset($_GET['code'])?$_GET['code']:"";
    $patientid = isset($_GET['patientid'])?$_GET['patientid']:"";
    $postid = isset($_GET['speccode'])?$_GET['speccode']:"";
    $prevpage = "page3.php";
    $nextpage = "";
    $errorpage = $prevpage;

    if(isset($_REQUEST['okremotedirection']))
    {
        /* ?><p>Запись проведена успешно.</p><?php */
        require_once("remotedirectionslist.inc");
        $record->getdata('', '');
        $direction = $record->directions[0];
        
        function crop70($num)
        {
            return substr("0000000".substr($num, 0, 7), -7, 7);
        }

        ?>

        <TABLE width="100%" border="0">
            <TR>
                <TD valign="bottom" style="vertical-align: bottom; "><?php echo isset($_SESSION['user_lpu'])?$_SESSION['user_lpu']:""; ?></TD>
                <TD valign="bottom" style="vertical-align: bottom; " align="right">
                <!-- IMG src="scode.php?scode=1254984" alt="ШтрихКод" -->
                <IMG src="barcode/image.php?code=<?php echo crop70($direction->number); ?>&style=68&width=150&height=40&xres=1&font=5" alt="ШтрихКод">
                </TD>
            </TR>
            <TR>
                <td colspan="2"><hr /></td>
            </TR>
            <TR>
                <TD colspan="2" align="center" class="big_text_black">
                    Запись № <?php echo $direction->number; ?> от <?php echo MikronDateTime::BeautifulDate(strtotime($direction->date), true); ?>г.
                    <!-- br>в <?php echo $_SESSION['name2']; ?> -->
                </TD>
            </tr>
        </TABLE>
        <TABLE border="0" width="100%">
            <TR>
            <TD>
                <TABLE>
                    <TR><TD><font class="text_grey">Ф.И.О.:</font></TD><TD>&nbsp;</TD><TD class="utext"><?php echo $direction->patient->fio;?></TD></TR>
                    <TR><TD><font class="text_grey">Дата рождения:</font></TD><TD>&nbsp;</TD><TD class="utext"><?php echo $direction->patient->birthday;?></TD></TR>
                    <TR><TD><font class="text_grey">Документ:</font></TD><TD>&nbsp;</TD><TD class="utext"><?php echo $direction->patient->document;?></TD></TR>
                    <TR><TD><font class="text_grey">Полис ОМС:</font></TD><TD>&nbsp;</TD><TD class="utext"><?php echo $direction->patient->policy;?></TD></TR>
                    <?php if($direction->director != "")
                    {
                        ?>
                        <TR><TD><font class="text_grey">Направлен из:</font></TD><TD>&nbsp;</TD><TD class="utext"><?php echo $direction->director;?></TD></TR>
                        <TR><TD><font class="text_grey">Занятость:</font></TD><TD>&nbsp;</TD><TD class="utext"><?php echo $direction->patient->employment;?></TD></TR>
                        <?php
                    }
                    ?>
                </TABLE>
            </TD>
            </TR>
            <TR>
                <TD style="padding-top: 1em;">
                    На прием к специалистам:
                    <TABLE class="print_table" width="100%" border="0" cellspacing="0" cellpadding="3">
                    <TR>
                        <TD class="print_cap1"><nobr>Врач/Отделение</nobr></TD>
                        <TD class="print_cap2">Специальность</TD>
                        <TD class="print_cap2"><nobr>Часы приема</nobr></TD>
                        <TD class="print_cap2"><nobr>Назначенное время*</nobr></TD>
                    </TR>
                    <?php
                        foreach($direction->entries as $entry)
                        {
                            ?>
                                <TR>
                                    <TD class="print_cell1" width="34%"><?php echo $entry->doctorfio;?>
                                    <br /><font class="text_grey"><?php echo $entry->division;?></font>
                                    </TD>
                                    <TD class="print_cell2" width="32%"><?php echo $entry->speciality;?></TD>
                                    <TD class="print_cell2" width="14%" align="center" style="white-space: nowrap; vertical-align: middle;">
                                        <nobr>
                                        <?php
                                        echo MikronDateTime::BeautifulWeekDayName(strtotime($entry->date), false);
                                        echo '<br />', $entry->surgery;
                                        ?>
                                        </nobr>
                                    </TD>
                                    <TD class="print_cell2" width="20%" align="center" style="white-space: nowrap; vertical-align: middle;">
                                        <nobr>
                                        <?php echo MikronDateTime::BeautifulDate(strtotime($entry->date), true);?>
                                        <br /><?php echo date('H:i', strtotime($entry->time));?>
                                        </nobr>
                                    </TD>
                                </TR>
                            <?php
                        }
                    ?>
                    </TABLE>
                    В назначенное время Вам необходимо подойти к указанному 
                    специалисту. В регистратуру не обращаться.
                    <!--
                    <p><font class="print_footer">* Вам необходимо получить талон<?php if(count($direction->entries)>1){?>ы<?php }?>
                     в регистратуре не позднее назначенного времени для
                    <?php if(count($direction->entries)>1){?>указанных специалистов.<?php }else{?>указанного специалиста.<?php }?>
                    -->
                     <br /><br />Адрес учреждения: <?php echo $record->address; ?>
                     </font></p>
                </TD>
            </TR>
        </table>
        <p>
        <table>
        <tr>
            <td align="center" width="84">
            <a onclick="printThisPage(); return false;" href="#print">
                <img src="/images/print.png" width="48" height="48">
                <br />Распечатать
            </a>
            </td>
            <td align="center" width="84">
            <a href="/remoterecord/" title="Кабинет">
                <img src="/images/home.png" width="48" height="48">
                <br />Кабинет
            </a>
            </td>
        </tr>
        </table>
        </p>
        </p>
        
        <?php
    }

?>

    <script type="text/javascript">
        <!--
        function printThisPage()
        {
            if (document.all)
            {
                var OLECMDID_PRINT = 6;
                var OLECMDEXECOPT_DONTPROMPTUSER = 2;
                var OLECMDEXECOPT_PROMPTUSER = 1;
                var OLECMDID_PRINT2                 = 49;
                var OLECMDID_PRINTPREVIEW2          = 50;
                var OLECMDID_PRINTPREVIEW           = 7;
                var OLECMDID_PAGESETUP              = 8; 
                var WebBrowser = "<OBJECT style='display: none;' ID=\"WebBrowser1\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></OBJECT>";
                document.body.insertAdjacentHTML("beforeEnd", WebBrowser);
                // WebBrowser1.ExecWB(OLECMDID_PAGESETUP, OLECMDEXECOPT_PROMPTUSER);
                WebBrowser1.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER);
                WebBrowser1.outerHTML = "";
            }
            else
            {
                self.print();
            }
        }
        file://-->
    </script>
<?php $mikron->Page->EndBody();?>